package com.example;

/**
 * 遍历10000以内所有质数
 *
 * @Author: wanqian
 * @Date: 2021/1/24 11:27
 */
public class PrimeNumberDemo {

    public static void main(String[] args) {
        int num = 0;
        label:
        for (int i = 2; i <= 10000; i++) {
            //从2到i的平方是否存在可除尽的数
            for (int j = 2; j <= Math.sqrt(i); j++) {
                //遇到可除尽的数则跳出本次循环
                if (i % j == 0) {
                    continue label;
                }
            }
            System.out.println(i);
            num++;
        }
        System.out.printf("一共有%d个质数", num);
    }
}
